package main

import (
	"encoding/json"
	"fmt"
)

type Student struct {
	ID     int
	Gender string
	Name   string
	Sno    string
}

func main() {
	var s1 = Student{
		ID:     12,
		Gender: "男",
		Name:   "李四",
		Sno:    "s001",
	}
	fmt.Printf("%#v\n", s1)

	jsonByte, _ := json.Marshal(s1)
	jsonStr := string(jsonByte)
	fmt.Printf("%v", jsonStr)

	fmt.Println("\ndeserialize...")
	var jsonStr1 = `{"ID":12,"Gender":"男","Name":"李四","Sno":"s001"}` // 使用反引号`可方便在多个引号"下不需要使用转义符号来表示其他引号
	var s2 Student
	err := json.Unmarshal([]byte(jsonStr1), &s2)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Printf("%#v\n", s2)
	fmt.Println(s2.Name)
}
